{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Comments (largely compiled by Markus Demleitner)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "While learning python is great, having programming skills is even better. Here, are mentioned a few of the virtues that will make you a good programmer." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Read** – Reading is the most important skill for *writing* programs.\n", "\n", "*Read error messages* – Good error messages actually tell you what's wrong. If you don't understand them, try to get an understanding. That's one of the cases when it's a good idea to google an error message. *Do not* blindly edit until an error message goes away.\n", "\n", "*Read documentation* – Python's library documentation (http://docs.python.org, or the python-doc package on most open system for local usage) is fairly good and readable. Before you use a module, skim over its docs, before you use a function, have a look there (and see below for ipython's ?). Refuse the temptation to guess.\n", "\n", "*Read other people's code* – Programming is non-obvious. Just as you have to read novels to write *good* texts, read and try to understand code passed to you (or perhaps just library code, which tends to be „good” in one way or another). The least it will do is show you what not to do if you'd like other people to understand your program." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Plan** what you write, i.e., think a bit about what you want to write. Putting it into a little text doesn't hurt at all (sentences of that text could become functions). But be aware that you probably thought wrong and you may have to *throw away* prototypes later. Programming is non-obvious, in particular with hard problems, you won't get it right the first time. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Think** before copying code. It is not easy to resist the temptation to blindly google error messages and code snippets. There is some serious expertise on stackoverflow. But at least one has to try to *understand* what the snippet is and does before pasting it. And whether it actually fits the problem at hand." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Zen of Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A text on the philosophy of programming is built right into your python interpreter:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The Zen of Python, by Tim Peters\n", "\n", "Beautiful is better than ugly.\n", "Explicit is better than implicit.\n", "Simple is better than complex.\n", "Complex is better than complicated.\n", "Flat is better than nested.\n", "Sparse is better than dense.\n", "Readability counts.\n", "Special cases aren't special enough to break the rules.\n", "Although practicality beats purity.\n", "Errors should never pass silently.\n", "Unless explicitly silenced.\n", "In the face of ambiguity, refuse the temptation to guess.\n", "There should be one-- and preferably only one --obvious way to do it.\n", "Although that way may not be obvious at first unless you're Dutch.\n", "Now is better than never.\n", "Although never is often better than *right* now.\n", "If the implementation is hard to explain, it's a bad idea.\n", "If the implementation is easy to explain, it may be a good idea.\n", "Namespaces are one honking great idea -- let's do more of those!\n" ] } ], "source": [ "import this" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }